package br.com.lambdacore.test.powermock.builder;

import java.lang.reflect.ParameterizedType;

import org.easymock.classextension.EasyMock;

public abstract class MockBuilder<T> extends Builder<T> {

	@SuppressWarnings("unchecked")
	public <E extends MockBuilder<T>> E createMock() {
		this.setObject(EasyMock
				.createMock((Class<T>) ((ParameterizedType) this.getClass()
						.getGenericSuperclass()).getActualTypeArguments()[0]));
		return (E) this;
	}

	public T replay() {
		T mock = this.getMock();
		EasyMock.replay(mock);
		return mock;
	}

	protected T getMock() {
		return this.build();
	}

}
